package color.koitq.picker.fragment;

import android.content.Intent;
import android.view.View;
import android.widget.ImageView;
import android.widget.Toast;

import com.qmuiteam.qmui.widget.QMUITopBarLayout;

import butterknife.BindView;
import butterknife.OnClick;
import color.koitq.picker.BuildConfig;
import color.koitq.picker.R;
import color.koitq.picker.activty.FeedbackActivity;
import color.koitq.picker.activty.PrivacyActivity;
import color.koitq.picker.ad.TTAdManagerHolder;
import color.koitq.picker.base.BaseFragment;

public class SettingFragment extends BaseFragment {

    @BindView(R.id.topbar)
    QMUITopBarLayout topBar;
    @BindView(R.id.qib_user_notice)
    ImageView qib_user_notice;

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_setting_ui;
    }

    @Override
    protected void init() {
        topBar.setTitle("我的");
            if (TTAdManagerHolder.getNoticeState()) {
                qib_user_notice.setImageResource(R.mipmap.icon_set_notice_open);
            } else {
                qib_user_notice.setImageResource(R.mipmap.icon_set_notice_close);
            }
            if ("vivo".equals(getString(R.string.channel))) {
                qib_user_notice.setVisibility(View.VISIBLE);
            } else {
                qib_user_notice.setVisibility(View.GONE);
            }
    }

    @OnClick({R.id.feedback, R.id.policy, R.id.layoutPrivacy, R.id.qib_user_notice})
    public void viewClick(View view) {
        switch (view.getId()) {
            case R.id.feedback:
                startActivity(new Intent(getActivity(), FeedbackActivity.class));
                break;
            case R.id.policy:
                PrivacyActivity.showRule(getContext(), PrivacyActivity.ShowUserAgreement);
                break;
            case R.id.layoutPrivacy:
                PrivacyActivity.showRule(getContext(), PrivacyActivity.ShowPolicy);
                break;
            case R.id.qib_user_notice:
                if (TTAdManagerHolder.getNoticeState()) {
                    qib_user_notice.setImageResource(R.mipmap.icon_set_notice_close);
                    TTAdManagerHolder.updateNotice(false);
                    Toast.makeText(getActivity(),"个性化推荐已关闭",Toast.LENGTH_SHORT).show();
                } else {
                    qib_user_notice.setImageResource(R.mipmap.icon_set_notice_open);
                    TTAdManagerHolder.updateNotice(true);
                    Toast.makeText(getActivity(),"个性化推荐已开启",Toast.LENGTH_SHORT).show();
                }
                break;
        }
    }

}
